Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

76
Visualizações
need to clarify things with x[y]

Can anyone explain in detail what exactly is going on in x[y] pairs? I tried console logging but no useful info. I am particularly interested in the operation within the if block.

let arr = ['a','b','b','c','c','c']
let obj = {}

arr.forEach((element) => {
    if (obj[element]){
        obj[element]++
    }else{
        obj[element] = 1
    }
})
console.log(obj) //{a: 1, b: 2, c: 3}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

so the IF blocks:

if(obj[element]) just means if element exists as a key in obj. Here, if element does not exist within obj, create a new key called element, assign it the value of 1 (currently one instance of it existing) If element exists as a key within obj, add 1 to the key element in obj (to increase the count)

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda